package moodish.client;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

import moodish.dummy.ClientCommDummy;

public class Window_Option extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private JPanel contentPane;
	private JComboBox<String> txtMood;
	private String[] moodStrings = { "Online", "Cheated", "Confused",
			"Clueless", "Annoyed", "Paranoid", "Sleepy", "Wonderful", "Hungry",
			"Careless", "Tired", " At ease", "Frazzled", "Content", "Loved",
			"Happy", " Needy", "Determined", "Accepted", "Uncomfortable",
			"Challenged", "Creative", "Disgruntled", "Rundown", "Cheerful",
			"Shy", "Lonely", "Bored", "Good" };
	private JTextField txtDelFriend;
	private JTextField txtAddFriend;
	private JButton btnDeleteFriend = new JButton("Delete Friend");
	private JButton btnUpdateMood = new JButton("Update Mood");
	private JButton btnAddFriend = new JButton("Add Friend");

	private Listener listener = new Listener();

	private ClientCommDummy clientComm;

	private Window_Main window;

	/**
	 * Create the frame.
	 * 
	 * @param clientComm
	 * @param listener2
	 */
	public Window_Option(ClientCommDummy clientComm, Window_Main window) {
		this.setTitle("Options");
		this.clientComm = clientComm;
		this.window = window;
		this.setResizable(false);
		this.setLocation(600, 300);
		buildGui();

	}

	private class Listener implements ActionListener {

		@Override
		public void actionPerformed(ActionEvent e) {

			if (e.getSource().equals(btnAddFriend)) {
				if (window.checkNotFriend(txtAddFriend.getText())) {
					clientComm.friendship(txtAddFriend.getText());
					window.addFriend(txtAddFriend.getText());
				}
			} else if (e.getSource().equals(btnDeleteFriend)) {
				if (window.checkFriend(txtDelFriend.getText())) {
					clientComm.unfriendship(txtDelFriend.getText());
					window.deleteFriend(txtDelFriend.getText());
				}

			} else if (e.getSource().equals(btnUpdateMood)) {
				String mood = (String) txtMood.getSelectedItem();
				clientComm.sendMoodishMessage(mood);
				window.setMood(mood);

			}
		}
	}

	private void buildGui() {
		setBounds(100, 100, 451, 430);
		contentPane = new JPanel();
		contentPane.setBackground(Color.WHITE);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);

		txtMood = new JComboBox<String>(moodStrings);
		txtMood.setBounds(15, 73, 146, 26);
		contentPane.add(txtMood);

		JLabel lblUpdateMood = new JLabel("Update Mood");
		lblUpdateMood.setBounds(15, 53, 103, 20);
		contentPane.add(lblUpdateMood);

		btnUpdateMood.setBackground(new Color(230, 230, 250));
		btnUpdateMood.setBounds(233, 72, 146, 29);
		contentPane.add(btnUpdateMood);
		btnUpdateMood.addActionListener(listener);
		txtDelFriend = new JTextField();
		txtDelFriend.setBounds(15, 150, 146, 26);
		contentPane.add(txtDelFriend);
		txtDelFriend.setColumns(10);

		JLabel lblDeleteFriend = new JLabel("Delete Friend");
		lblDeleteFriend.setBounds(15, 128, 146, 20);
		contentPane.add(lblDeleteFriend);

		btnDeleteFriend.setBackground(new Color(230, 230, 250));
		btnDeleteFriend.setBounds(233, 149, 146, 29);
		contentPane.add(btnDeleteFriend);
		btnDeleteFriend.addActionListener(listener);
		txtAddFriend = new JTextField();
		txtAddFriend.setBounds(15, 233, 146, 26);
		contentPane.add(txtAddFriend);
		txtAddFriend.setColumns(10);

		btnAddFriend.setBackground(new Color(230, 230, 250));
		btnAddFriend.setBounds(233, 232, 146, 29);
		contentPane.add(btnAddFriend);
		btnAddFriend.addActionListener(listener);
		JLabel lblAddFriend = new JLabel("Add Friend");
		lblAddFriend.setBounds(15, 215, 146, 20);
		contentPane.add(lblAddFriend);

	}
}
